package mao.thinkinjava.concurency.myenum;

public class TestEnum {
    // enums/EnumClass.java
// Capabilities of the Enum class
    enum Shrubbery {
        //这里相当于new实例了。可以看做有有限实例的类。
        GROUND("ground"),
        CRAWLING("cramling"),
        HANGING("hanging");
        private String description;
        private Shrubbery(String s){
            this.description = s;
        }
        @Override
        public String toString() {
            return "Shrubbery{" +
                    "description='" + description + '\'' +
                    '}';
        }

    }
    public static class EnumClass {
        public static void main(String[] args) {
            Enum e = Shrubbery.CRAWLING;

            for(Shrubbery s : Shrubbery.values()) {
                //获得下标。
                System.out.println(
                        s + " ordinal: " + s.ordinal());
                System.out.print(
                        s.compareTo(Shrubbery.CRAWLING) + " ");
                System.out.print(
                        s.equals(Shrubbery.CRAWLING) + " ");
                System.out.println(s == Shrubbery.CRAWLING);
                System.out.println(s.getDeclaringClass());
                Class clazz = s.getDeclaringClass();
                Class<? extends Shrubbery> aClass = s.getClass();
                System.out.println(aClass);
                Class superclass = clazz.getSuperclass();
                System.out.println(superclass);
                System.out.println(s.name());
                System.out.println("********************");
            }
// Produce an enum value from a String name:
            for(String s :
                    "HANGING CRAWLING GROUND".split(" ")) {
                Shrubbery shrub =
                        Shrubbery.valueOf(Shrubbery.class, s);
                System.out.println(shrub);
            }
        }
    }

    public static void main(String[] args){
        EnumClass.main(args);
    }
}
